<?php
// 订单模型
//注：selectById4User与selectMyOrderById两个方法应该保留一个？
class OrderService extends Service {
	public $TAG = 'OrderService';
	
	
	/**
	 * 通过订单id查询对应的商品的相关信息。
	 * $result[$vo['order_id']]=array(	"goods_title"=>$vo['goods_title']
											,"goods_id"=>$vo['goods_id']
											,"partner_id"=>$vo['partner_id']
											,"shelf_id"=>$vo['shelf_id']
											,"sender_name"=>$vo['sender_name']
											,"sender_mobile"=>$vo['sender_mobile']
											);
	 * @param array $ary_shelfid	一维数组
	 * @return	$result[shelf_id]=array("goods_title"=>*****)形式的数组
	 */
	public function selectORelInfoByIds($ary_orderid){
		Log::record($TAG.'.selectORelInfoByIds('.$ary_orderid.')',Log::DEBUG,Log::FILE);
		Log::save(); 
		$str_ids = implode(',',$ary_orderid);
		$db_prefix = C('DB_PREFIX');
		$data = M('')->query(	"select g.title as 'goods_title',g.id as 'goods_id',g.goods_icon as 'goods_icon',g.get_type as 'goods_get_type',g.partner_id as 'partner_id',s.id as 'shelf_id',p.title as 'partner_title',p.phone as 'partner_phone',p.mobile as 'partner_mobile',"
								."o.id as 'order_id',o.pay_state as 'pay_state',o.order_state as 'order_state',o.user_id as order_user_id ,o.enable as 'order_enable',o.sender_name as 'sender_name',o.sender_mobile as 'sender_mobile' from {$db_prefix}goods g,{$db_prefix}goods_shelf s,{$db_prefix}order o ,{$db_prefix}partner p ".
								" where o.id in ( {$str_ids} ) and o.shelf_id=s.id and g.id=s.goods_id and p.id=g.partner_id ;");

		foreach($data as $vo){
			$can_send = true;
			if( $vo['pay_state']   =='uppay' ) 	$can_send = false;
			if( $vo['order_state'] =='Y' ) 		$can_send = false;
			if( $vo['order_enable']=='N' ) 		$can_send = false;
			$result[$vo['order_id']]=array(	"goods_title"	=>	$vo['goods_title']
											,"goods_id"		=>	$vo['goods_id']
											,"goods_icon"	=>	$vo['goods_icon']
											,"partner_id"	=>	$vo['partner_id']
											,"partner_title"=>	$vo['partner_title']
											,"partner_phone"=>	$vo['partner_phone']
											,"partner_mobile"=>	$vo['partner_mobile']
											,"shelf_id"		=>	$vo['shelf_id']
											,"sender_name"	=>	$vo['sender_name']
											,"sender_mobile"=>	$vo['sender_mobile']
											,"pay_state"	=>	$vo['pay_state']
											,"order_state"	=>	$vo['order_state']
											,"order_user_id"=>	$vo['order_user_id']
											,"order_enable"	=>	$vo['order_enable']
											,"can_send"		=>	$can_send
											,"goods_get_type"=>	$vo['goods_get_type']  //添加这个是为了添加额外信息（电话确认收货地点等信息）
											);
		}
		return $result;
	}
	
	
	/** 确认订单，生成相应数据。如果新增失败，数据回滚。返回0，否则返回生成的订单id。
	 * 	@param		$order_data		订单相关数据。
	 * 								格式说明：	$order_data['shelf']					=	$productdata;
	 * 											$order_data['receivers']['data'] 		= 	$receivers;
												$order_data['receivers']['send_total_no'] 	= 	$send_total_number_;
												$order_data['sender'] = $sender;
																$sender['send_format']		=	$send_format;
																$sender['sender_mobile']	=	$sender_mobile;
																$sender['sender_name']		=	$sender_name;
												$order_data['smsdata'] 					= 	$smsdata[0];//stdClass对象
																$smsdata = str_replace('\\"',"\"",$smsdata);
																$smsdata = json_decode($smsdata);
												$order_data['txtdata']['txt_content'] 	= 	$txt_content;
												$order_data['payment']['paid_money'] 	= 	$order_data['receivers']['total_no']*$order_data['shelf']['shelf_out_price'];
												$order_data['payment']['gain_credit']	= 	$order_data['receivers']['total_no']*$order_data['shelf']['shelf_gain_credit'];
												$order_data['payment']['used_credit'] 	= 	$order_data['receivers']['total_no']*$order_data['shelf']['shelf_gain_credit'];
			
									实例数据：
										($order_data) = array(5) {
														 ["shelf"] => array(33) {
															    ["shelf_id"] => string(1) "6"
															    ["shelf_out_price"] => string(5) "30.00"
															    ["shelf_market_price"] => string(5) "35.00"
															    ["shelf_gain_credit"] => string(3) "100"
															    ["shelf_total_number"] => string(3) "100"
															    ["shelf_send_number"] => string(1) "0"
															    ["shelf_off_time"] => string(10) "1303444800"
															    ["shelf_on_time"] => string(10) "1302062400"
															    ["shelf_enable"] => string(1) "Y"
															    ["shelf_is_delete"] => string(1) "N"
															    ["goods_id"] => string(2) "10"
															    ["goods_title"] => string(9) "麻辣烫"
															    ["goods_summary"] => string(45) "好吃得很！！！！！！！！！！！"
															    ["goods_icon"] => string(26) "goods/10/4d99f67e93dfb.gif"
															    ["goods_detail"] => string(104) "<p><img alt="" margin:="" src="http://www.mysite.com/data/uploads/2011/0405/12/4d9a9645383f6.jpg" /></p>"
															    ["goods_sort_id"] => string(5) "snack"
															    ["goods_send_number"] => string(1) "0"
															    ["goods_total_number"] => string(1) "0"
															    ["goods_expire_time"] => string(10) "1304136000"
															    ["goods_start_time"] => string(10) "1301976000"
															    ["goods_ctime"] => string(10) "1301935742"
															    ["goods_mtime"] => string(10) "1302519760"
															    ["goods_insert_admin_id"] => string(1) "1"
															    ["goods_enable"] => string(1) "Y"
															    ["goods_is_delete"] => string(1) "N"
															    ["partner_id"] => string(2) "14"
															    ["partner_title"] => string(9) "辛巴克"
															    ["partner_sort_id"] => string(4) "food"
															    ["partner_brand_icon"] => string(28) "partner/14/4d99982c60061.jpg"
															    ["partner_enable"] => string(1) "Y"
															    ["partner_is_delete"] => string(1) "N"
															    ["stat_send_number"] => string(1) "0"
															    ["stat_total_number"] => string(3) "100"
														 }
														 ["receivers"] => array(2) {
															    ["data"] => array(1) {
																      [0] => array(4) {
																        [0] => string(11) "13822222222"
																        [1] => string(1) "1"
																        [2] => string(10) "2011-04-16"
																        [3] => string(1) "0"
																      }
															    }
															    ["send_total_no"] => int(1)
														 }
														 ["sender"] => array(3) {
															    ["send_format"] => string(3) "sms"
															    ["sender_mobile"] => string(11) "13222222222"
															    ["sender_name"] => string(6) "eee332"
														 }
														 ["smsdata"] => object(stdClass)#10 (5) {
															    ["xyOffset"] => string(10) "2px,-152px"
															    ["smsimg"] => string(34) "templet/sms/system/1302290004.jpeg"
															    ["smstext"] => string(0) ""
															    ["smsicon"] => string(35) "/Public/Js/smsEditer/icon/test3.gif"
															    ["textcolor"] => string(0) ""
														 }
														 ["txtdata"] => array(1) {
														    	["txt_content"] => string(0) ""
														 }
														 ["payment"] => array(6) {
															    ["total_price"] => float(30)
															    ["gain_credit"] => int(100)
															    ["used_credit"] => int(100)
															    ["out_price"] => string(5) "30.00"
															    ["total_no"] => int(1)
															    ["pay_money"] => float(29)
														 }			 
										}										
	 * 											
	 *	@return 	json数据格式，status->状态  msg->描述  
	**/
	public function do4UserSubmitOrder($order_data){
		Log::record('提交新的订单',Log::K_ORDER,Log::FILE);
		Log::record(parseAry2Str($order_data),Log::K_ORDER,Log::FILE);
		$checkremain = $this->_checkRemain($order_data["shelf"]['goods_id'],$order_data["payment"]["total_no"]);
		if(!$checkremain){
			Log::record('商品剩余量不足，订单提交失败！',Log::K_ORDER,Log::FILE);
			Log::save(); 
			return 0;
		}
		$couponDao = model('Coupon');
		
		//开始事务
		$couponDao->startTrans();
		
		$ifrollback = false;
		/** 录入订单 **/
		$id = model('Order')->addOrder($order_data["shelf"]['shelf_id']
										,$_SESSION['mid'],$order_data["sender"]['sender_name'],$order_data["sender"]['sender_mobile']
										,$order_data["payment"]["total_no"],$order_data["payment"]["pay_money"]
										,$order_data["payment"]["used_credit"],$order_data["payment"]["gain_credit"]);
		/** 录入优惠券支付信息 **/
		if($order_data['cashcoupon']['passcode']){
			$ruledata['goods_id'] = $order_data['shelf']['goods_id'];
  			$ruledata['partner_id'] = $order_data['shelf']['partner_id'];
  			$ruledata['amount'] = $order_data['payment']['total_price'];
			$ccresult = service('CashCoupon')->doUse($order_data['cashcoupon']['passcode'],$ruledata);
			Log::record('新增订单：代金券：result->'.parseAry2Str($ccresult),Log::K_ORDER,Log::FILE);
			//直接录入支付数据
			if($ccresult['status']==1){
				$ary_payinfo=array(	'trade_no'=>''//当用现金账户支付时，交易Id将在录入前自动维护
			 						,'pay_type'=>'pay_order'
				 					,'item_id'=>$id
									,'total_fee'=>$order_data['cashcoupon']['amount']
				 					,'service'=>'couponpay'
				 					,'return_info'=>$order_data['cashcoupon']['passcode']
				 					,'paytime'=>time()
				  					,'uid'=>$_SESSION['mid']
				 			 	);
			}
			//dump($ary_payinfo);
			//unset($result);
		}
		//录入支付数据
		if(!empty($ary_payinfo)){
			$payresult = service('Pay')->addPayInfo($ary_payinfo);
			Log::record('新增订单：支付结果：result->'.parseAry2Str($payresult),Log::K_ORDER,Log::FILE);
		}
		
		
		Log::record('新增订单：id->'.$id,Log::K_ORDER,Log::FILE);
		Log::record('订单数据：mid->'.$_SESSION['mid']
								."\n\r  sender->".parseAry2Str($order_data["sender"])
								."\n\r  payment->".parseAry2Str($order_data["payment"])
							,Log::K_ORDER,Log::FILE);								
		/** 录入收礼人 **/
		if(!empty($id)){
			if($order_data["sender"]["send_format"]=='mms'){
				//生成sms图片，保存到指定目录下sms/send下。
				$smsImgDao 	= service('SmsImg');
				$namecard 	= $smsImgDao->saveSmsImg4Send($id,$order_data["smsdata"]);	
			}
			$couponno = $couponDao->addCoupon($id,$order_data["shelf"]['goods_id'],$order_data["receivers"]['data']
													,$order_data["sender"]["send_format"]
													,$namecard,$order_data["txtdata"]["txt_content"]);	
			Log::record('新增礼券：'.$couponno.'个',Log::K_ORDER,Log::FILE);	
			Log::record("礼券数据：mid->".$_SESSION['mid']
									."\n\r  receivers->".parseAry2Str($order_data["receivers"])
									."\n\r  send_format->".$order_data["sender"]["send_format"]
									."\n\r  namecard->".$namecard
									."\n\r  txt_content->".$order_data["txtdata"]["txt_content"]
							,Log::K_ORDER,Log::FILE);								
			
			if( count($order_data["receivers"]['data']) != $couponno ){
				Log::record("生成的礼券个数与实际接收者不等，数据回滚！  生成->[".$couponno."] 期望->[".count($order_data["receivers"]['data'])."] ",Log::K_ORDER,Log::FILE);	
				$ifrollback = true;
			}
		}else{
			Log::record('订单录入失败，数据回滚！',Log::K_ORDER,Log::FILE);	
			$ifrollback = true;
		}
		if($ifrollback){
			$id = 0;
			$couponDao->rollback(); 
			Log::record('数据回滚成功！',Log::K_ORDER,Log::FILE);	
		}else{
			$couponDao->commit(); 
			Log::record('订单新增成功！',Log::K_ORDER,Log::FILE);	
		}
		Log::save(); 
		return $id;
	}
	
	
	/**
	 * 检查剩余量
	 */
	private function _checkRemain($goods_id,$quantity){
		$goods_remain = service('Product')->getRemain($goods_id);
		if($goods_remain>=$quantity)return true;
		return false;
	}
	
	
	/**用户撤销未付款订单。或 用户删除，不显示已付款订单。
	 * 
	 * @param unknown_type $order_id
	 * @param unknown_type $user_id
	 */
	public function delete4User($order_id){
		$result['status']=0;
		$user_id = $_SESSION['mid'];
		$orderinfo = $this->get4UserById($order_id);
		if(empty($orderinfo)){
			$result['msg'] = '订单不存在！';
			return $result;
		}

		if($orderinfo['pay_state']=='pay'){	//已支付的订单，将订单设置为不显示。
			$no = model('Order')->userUnshowOrder($order_id,$user_id);
			if($no){
				$result['status']	=	1;
				$result['msg']		=	'删除订单数据成功！';
			}else{
				$result['status']	=	0;
				$result['msg']		=	'删除订单数据失败！';
			}
		}else{ 	//未支付的订单，将订单设置未撤销、取消礼券、并刷新现金帐户。
			$orderdao = model('Order');
			$orderdao->startTrans();
			$no = $orderdao->userDeleteOrder($order_id,$user_id);
			service('Pay')->delete4UserByOid($order_id);
			if($no){
				$no = model('Coupon')->chancelCoupon($order_id,'用户撤销订单！');
				if($no){
					$orderdao->commit(); 
					service('UserAccount')->refresh4UserCash();
					$result['status']	=	1;
					$result['msg']		=	'撤销订单成功！';
				}else{
					$orderdao->rollback(); 
					$result['status']	=	0;
					$result['msg']		=	'撤销'.K('SP_COUPON_NM').'失败，撤销订单失败！';
				}
			}else{
				$result['status']	=	0;
				$result['msg']		=	'删除订单失败！';
			}
		}
		
		return $result;
	}
	
	/**用户删除，不显示已付款订单。
	 * 
	 * @param unknown_type $order_id
	 * @param unknown_type $user_id
	 */
	public function userUnshowOrder($order_id,$user_id){
		$no = model('Order')->userUnshowOrder($order_id,$user_id);
		return $no;
	}
	
	
	/**用户删除订单
	 * 
	 * @param unknown_type $order_id
	 * @param unknown_type $user_id
	 */
	public function adminDeleteOrder($order_id,$admin_id,$remark){
		$no = model('Order')->adminDeleteOrder($order_id,$admin_id,$remark);
		return $no;
	}
	
	
	/** 用于系统内部，需要查询订单时使用。该方法除了ID不限制任何其他附加条件。
	 * 
	 * @param String $order_id
	 * @return NULL | 订单数据(单条)
	 **/
	public function get4SysById($order_id){
		if(empty($order_id))return null;
		$where['id']			=$order_id;
		//$where['order_state']	='N';//` enum('Y','N') NOT NULL DEFAULT 'Y' COMMENT '订单状态，是否撤销（未支付的可撤销）。由用户执行的操作',
	  	$order = model('Order')->where($where)->find();
	  	Log::record('OrderService.get4SysById()sql='.(model('Order')->getLastSql()),Log::DEBUG,Log::FILE);
		Log::save();
		return $order;
	}
	
	
	/** 通过ID，查询当前登陆用户的订单。
	 *  通过查询条件加入用户id来设置用户只能查看自己的订单。
	 * 
	 * @param String $order_id
	 * @return NULL | 订单数据(单条)
	 */
	public function get4UserById($order_id){
		if(empty($order_id))return null;
		$where['id']			=$order_id;
		$where['user_id']		=$_SESSION['mid'];
		$where['is_show']='Y';
		$where['order_state']	='N';//` enum('Y','N') NOT NULL DEFAULT 'Y' COMMENT '订单状态，是否撤销（未支付的可撤销）。由用户执行的操作',
	  	$order = model('Order')->where($where)->find();
		return $order;
	}
	
	/** 当前登录用户查询其所有订单。
	 *  通过查询条件加入用户id来设置用户只能查看自己的订单。
	 * @param String $stype		空或all=查询全部		pay=查询已付款的		unpay=查询未付款的
	 * @param int $limit
	 * @return 返回KPage分页数据 selectOrder4LoginUser
	 */
	public function search4User($stype='all',$limit=15,$mobile=null){
		$where['user_id']=$_SESSION['mid'];
		if($stype=='pay'){
			$where['pay_state']=$stype;
		}
		if($stype=='unpay'){
			$where['pay_state']=$stype;
		}
		
		if($mobile!=null)$where['sender_mobile']=$mobile;
		$where['order_state']='N';
		$where['is_show']='Y';
		$where['enable']='Y';
		$order='pay_time desc , ctime desc';
		$orderdao = M('Order');
		$pagedata = $orderdao->kPageQuery($where,$order,$limit);
		//echo $mobile.'--'.$orderdao->getLastSql();
		return $pagedata;
	}
	
	/**
	 * 	当前登录用户查询其所有订单。
	 *  通过查询条件加入用户id来设置用户只能查看自己的订单。
	 * @param String $stype		空或all=查询全部		pay=查询已付款的		unpay=查询未付款的
	 */
	public function count4User($stype='all'){
		$where['user_id']=$_SESSION['mid'];
		if($stype=='pay'){
			$where['pay_state']=$stype;
		}
		if($stype=='unpay'){
			$where['pay_state']=$stype;
		}
		$where['order_state']='N';
		$where['is_show']='Y';
		$result = M('Order')->where($where)->limit(1)->field('count(1) as count')->find();
		$count	=	$result['count'];
		return $count;
	}
	
	
	/** 支付订单，该方法将通过订单号自动查找支付记录里是否有相关支付数据。若有相关数据并请订单未支付则更新订单为已支付，并激活礼券。
	  * 支付订单。执行此方法前须确保支付的有效性（即支付已成功）。
	 * 流程：	1。判断订单是否未支付、及有效性。
	 * 					包括：	1。方法所需参数不为空。
	 * 							2。对应支付记录是否存在，支付记录与该订单是否对应。
	 * 							3。订单是否有效，是否已支付，金额是否相同。
	 * 			2。再次判断支付预订单是否对应（对应订单号，支付金额等）。
	 * 			3。修改订单为已支付，激活礼券。
	 * 			4。结束确认支付操作。
	 * 
	 * @param String $pay_id
	 * @param String $order_id
	 * @return $result['status'] 	= -1;$result['msg'] 		= '数据有误！'; -1表示数据有误或检查不通过。1表示操作成功。0表示录入失败。
	 */
	public function do4UserPayOrder($order_id){
		Log::record('<<<<<支付订单['.$order_id.']支付ID['.$pay_id.']：开始--'.date('Y-m-d H:i:s'),Log::K_ORDER,Log::FILE);
		$result = $this->checkEffectiveBeforePay($order_id);
		$orderinfo = $result['data'];
		if($result['status']!=1){
			Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
			Log::save(); 
			return $result;
		}
		
		//查询上架商品设置的兑换截止时间
		$shelf = M('GoodsShelf')->where(array('id'=>$orderinfo['shelf_id']))->find();
		
		
		$payinfos = service('Pay')->selectItemPay($order_id,'pay_order','Y','N');
		//dump($payinfo);
		/**  屏蔽掉是为了可以代金券付全额。对付代金券的限制则在代金券中设置。
		if(empty($payinfos)||count($payinfos)<1){
			$result['msg'] 		= '无对应支付记录！未付款！';
			Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
			Log::save(); 
			return $result;
		}
		**/
		//计算支付的总金额
		//$total_fee=service('Pay')->countOrderPaiedAmount($order_id,'pay_order','Y','Y');
		$total_fee = 0;
		foreach($payinfos as $vop){
			$total_fee = $total_fee+$vop['total_fee'];
		}
		$total_fee=$orderinfo['had_pay_fee']+$total_fee;
		Log::record('>>>>>支付结果:->已支付：['.$orderinfo['had_pay_fee'].'元] 本次支付：['.$total_fee.'元]',Log::K_ORDER,Log::FILE);                     	
		if($total_fee!=$orderinfo['paid_money']){
			$result['status']	= 0;
			$result['msg'] 		= "该支付额度与订单需支付额度不一致，无法完成订单支付！已支付：[".($total_fee)." 元]  订单需支付：[{$orderinfo['paid_money']} 元]";
			Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
			Log::save(); 
			return $result;
		}
		
		unset($result);
		$coupondao = model('Coupon');
		$coupondao->commit(); 
		$coupondao->startTrans();
		$no = model('Order')->upd2Payed($order_id);
		if($no){
			//增加积分纪录
			//确认支付记录。
			service('Pay')->doConfrimPay($order_id,'pay_order');
			//激活礼券
			
			if(empty($shelf['exchange_time'])){
				$exchage_time = time()+(C('COUPON_EXPIRED_DATE')*24*60*60);
			}else{
				$exchage_time = $shelf['exchange_time'];
			}
			$no1 = $coupondao->update2Active($order_id,time(),$exchage_time);
			if($no){
				$result['status'] 	= 1;
				$result['msg'] 		= '支付订单成功！';
			}else{
				$result['status'] 	= 0;
				$result['msg'] 		= '激活'.K('SP_COUPON_NM').'失败！';
			}
			
		}else{
			$result['status'] 	= 0;
			$result['msg'] 		= '支付订单失败！';
		}
		
		if($result['status']!=1){
			$id = 0;
			$coupondao->rollback(); 
			Log::record('事务回滚成功！',Log::K_ORDER,Log::FILE);	
		}else{
			$coupondao->commit(); 
			Log::record('事务提交成功！',Log::K_ORDER,Log::FILE);	
		}
		Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
		Log::save(); 
		
		$result['data']['payinfo'] 		= $payinfos;
		$result['data']['shelfinfo'] 	= $shelf;
		$result['data']['orderinfo'] 	= $orderinfo;
		$result['data']['orderinfo']['total_fee'] 	= $total_fee;
		
		return $result;
	}
	
	
	/**
	 * 通过订单id查询送礼用户id数组
	 * @param array $oids
	 * @param int $limit
	 */
	public function select4UserUidsByOids($oids,$limit=10){
		if(empty($oids))return null;
		$map['id'] = array('in',$oids);
		$map['pay_state']='pay';
		$map['order_state']='N';
		$map['enable']='Y';
		$map['is_show']='Y';
		$uids = model('Order')->where($map)->field('DISTINCT user_id')->limit($limit)->findAll();
		return $uids;
	}
	
	/**
	 * 查询有效的并未撤销的订单是否已支付。
	 * @param unknown_type $order_id
	 */
	public function isOrderPaied($order_id,$uid=null){
		$map_1['id']=$order_id;
		if(!empty($uid))$map_1['user_id']=$uid;
		$map_1['pay_state']=array('eq','pay');$map_1['order_state']='N';$map_1['enable']='Y';
		$order = model('Order')->where($map_1)->find();
		if( $order!=null && !empty($order['id']) )return true;
		return false;
	}
	
	
	/**
	 * 支付前检查订单有效性。
	 * 检查：	1。是否存在。
	 * 			2。是否被管理员撤销。
	 * 			3。是否已支付。
	 * 			4。是否被用户撤销。
	 * 			5。是否被用户删除（不显示）。
	 */
	public function checkEffectiveBeforePay($oid,$orderinfo=null){
		if($orderinfo==null){
			if(!empty($oid)){
				$orderinfo = $this->get4UserById($oid);
			}
		}
		$result['status']	= 0;
		$result['data']	= $orderinfo;
		//加载已支付金额
		$_total_pay = service('Pay')->countOrderPaiedAmount($oid,'pay_order','Y','Y');
		$result['data']['had_pay_fee']	= $_total_pay;//已支付总额
		//dump($orderinfo);
		if(empty($orderinfo)){
			$result['msg'] 		= '无对应订单记录！';
			Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
			Log::save(); 
			return $result;
		}
		if($orderinfo['enable']=='N'){
			$result['msg'] 		= '订单被管理员撤销！<br>撤销说明：'.$orderinfo['remark'];
			Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
			Log::save(); 
			return $result;
		}
		if($orderinfo['pay_state']=='pay'){
			$result['msg'] 		= '订单已支付！';
			$result['paystatus'] 		= 'pay';//为了进一部便于判断订单是否是因为已支付所以才返回 status=0
			Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
			Log::save(); 
			return $result;
		}
		if($orderinfo['is_show']!='Y'){
			$result['msg'] 		= "该订单已删除！";
			Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
			Log::save(); 
			return $result;
		}
		if($orderinfo['order_state']!='N'){
			$result['msg'] 		= "该订单已被撤销！";
			Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
			Log::save(); 
			return $result;
		}
		
		$result['status']	= 1;
		$result['msg']	= '订单检查成功！';
		Log::record('>>>>>支付结果:->['.$result['msg'].']['.parseAry2Str($result).']',Log::K_ORDER,Log::FILE);
		Log::save(); 
		return $result;
	}
	
	
	//服务初始化
	public function init($data = '') {
	}
	
	
	//运行服务，系统服务自动运行
	public function run() {
	}
}
?>